/*
	Copyright 2007-2010 Petr Ohlidal

	This file is a part of GrobMaker

	GrobMaker is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	GrobMaker is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with GrobMaker.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef GROBMAKER_FILEINFO
#define GROBMAKER_FILEINFO

/** @file */

#include "../Global.hpp"
#include <string>

namespace GrobMaker{

class FileInfo{
public:

	static const int noIndex = -1; // Member constant
	fs::directory_entry entry;
	fs::file_status status;
	int index;

	FileInfo(): index(FileInfo::noIndex){}

	FileInfo(fs::directory_entry& entry):
		entry(entry)
	{
		std::string filename = entry.path().filename();
		this->index = FileInfo::parseFileNameIndex(filename);
		this->status = this->entry.status();
	}

	FileInfo(const fs::path& path){
		this->entry = fs::directory_entry(path);
		this->status = this->entry.status();
		std::string filename = path.filename();
		this->index = FileInfo::parseFileNameIndex(filename);
	}

	/**
	* Returns integer representation of numbers in filename.
	* Takes all digits, ignores all other characters.
	* @return The number or FileInfo::noIndex if there are no digits.
	*/
	static int parseFileNameIndex(const std::string& name);
};

} // namespace GrobMaker

#endif //#ifndef GROBMAKER_FILEINFO
